package cn.pkg.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

@RestController
public class RedisController {
    @Autowired
    private RedisTemplate redisTemplate;

    @GetMapping("/redis/get/{key}")
        public  Object get(@PathVariable("key") String key){
            return redisTemplate.opsForValue().get(key);
        }
//    未解决乱码问题，redisTemplate会把他序列化"\xac\xed\x00\x05t\x00\bzhangsan"
    @PostMapping("/redis/set/{key}/{value}")
    public Object set(@PathVariable("key") String key,
                      @PathVariable("value") String value){
         redisTemplate.opsForValue().set(key,value);
         return "set sucess";
    }
}
